package DataStructure.graph;

import DataStructure.linear.Stack;

public class TopoLogical {
    //顶点的拓扑排序
    private Stack<Integer> order;

    //构造拓扑的排序对象
    public TopoLogical(Digraph G){
        //穿件一个检测有向环的对象
        DirectedCycle cycle = new DirectedCycle(G);
        //如果没有环则进行顶点排序，创建一个顶点排序对象
        if(!cycle.hasCycle()){
            DepthFirstOrder depthFirstOrder = new DepthFirstOrder(G);

            order=depthFirstOrder.ReversePost();
        }
    }

    //判断是否有环
    public boolean isCycle(){
        return order==null;
    }

    //获取拓扑排序的所有顶点
    public Stack<Integer> order(){
        return order;
    }
}
